<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-28 16:21:26
 * @LastEditTime : 2019-12-19 09:56:08
 * @LastEditors  : Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <style type="text/css">
        .head {
            background: #ededed;
        }

        .van-nav-bar .van-icon {
            color: #000;
        }

        .van-nav-bar__title {
            color: #000;
            font-weight: 700;
        }

        .content {
            background: #fff !important;
        }

        .img {
            width: 47px;
            height: 47px;
            text-align: center;
            position: relative;
            border-radius: 6px;
            overflow: hidden;
        }

        .img img {
            width: 100%;
            height: 100%;
            vertical-align: middle;
        }

        .img-text {
            font-size: 14px;
            margin-top: 4px;
        }

        .van-cell__value {
            text-align: right;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" :title="'聊天信息(' + groupMember.length +')'" left-arrow @click-left="onClickLeft">

            </van-nav-bar>
            <div class="body-no-bottom">
                <div class="content">
                    <div>
                        <van-grid :column-num="5" :border="false">
                            <van-grid-item v-for="row in groupMember">
                                <div class="img">
                                    <img :src="row.HeadImg || '../../image/we_header.png'" />
                                </div>
                                <div class="img-text">{{row.UserName}}</div>
                            </van-grid-item>
                            <van-grid-item>
                                <div class="img" style="border:1px solid #bbbbbb;" @click="invitationPerson">
                                    <img src="../../image/g-add.png" />
                                </div>
                                <div class="img-text" style="visibility: hidden;">---</div>
                            </van-grid-item>
                        </van-grid>
                    </div>
                    <div style="border-top:5px solid #ededed;">
                        <van-cell title="群聊名称" :value="nowChatUserData.groupname || nowChatUserData.username"></van-cell>
                    </div>
                    <div style="border-top:5px solid #ededed;">
                        <van-button type="default" class="login-out" block @click="deleteGroup"><span
                                style="color:#cd1b21">删除并退出</span></van-button>
                    </div>
                </div>
                <van-loading v-if="showLoading" />
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'joinGroup'
        }, function (ret, err) {
            var userIDArray = ret.value.userIDArray;
            var obj = {
                groupId: vm.nowChatUserData.id,
                userIds: userIDArray.join(',')
            }
            FLD.ajax('joinGroup', obj, function (res) {
                layer.open({
                    content: '添加成功',
                    skin: 'msg',
                    time: 2
                });
                vm.getGroupUser();
            })
        })

        var nowChatUserData = api.pageParam.nowChatUserData;

        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                nowChatUserData: nowChatUserData,
                groupMember: []
            },
            created: function () {
                var that = this;
                that.getGroupUser();
            },
            methods: {
                getGroupUser() {
                    var that = this;
                    var obj = {
                        groupID: that.nowChatUserData.id
                    }
                    FLD.ajax('GetGroupUser', obj, function (res) {
                        that.groupMember = res.ds;
                    })
                },
                invitationPerson() {
                    var that = this;
                    api.openWin({
                        name: 'chatFriendList',
                        url: 'chatFriendList.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: {
                            isInvitation: 1
                        }
                    })
                },
                deleteGroup() {
                    var that = this;
                    that.$dialog.confirm({
                        title: '提示',
                        closeOnClickOverlay: true,
                        message: '是否确认退出该群并删除聊天记录?'
                    }).then(() => {
                        var obj = {
                            groupId: that.nowChatUserData.id
                        }
                        FLD.ajax('existsGroup', obj, function (res) {
                            api.sendEvent({
                                name: 'deleteGroup',
                                extra: {
                                    groupId: that.nowChatUserData.id
                                }
                            });
                            layer.open({
                                content: '退出成功!',
                                skin: 'msg',
                                time: 2,
                                end: function () {

                                    api.closeToWin({
                                        name: 'chat/chatList'
                                    })
                                }
                            });
                        })
                    }).catch(() => {

                    });

                },
                onClickLeft() {
                    api.closeWin();
                }
            }
        })
    }
</script>

</html>